using System;
using Randomize.Core.Exceptions;

namespace Randomize.Core.Generators
{
    public class IntGenerator : RangeGenerator<int>, IIntGenerator
    {
        public int? MinValue { get; set; }

        public int? MaxValue { get; set; }

        public IntGenerator(Random random) : base(random)
        {
        }

        protected override int GenerateRandomValue()
        {
            int max = this.MaxValue ?? int.MaxValue;
            int min = this.MinValue ?? int.MinValue;

            if (max < min)
            {
                throw new GenerationConfigurationException("Configured min value cannot be more than max");
            }

            return this.RandomInstance.Next(min, max);
        }
    }
}